<script setup lang="ts">
import { ref, onMounted } from "vue";

const weather = ref("加载中...");

onMounted(async () => {
  const lng = 116.397;
  const lat = 39.908;

  const res = await fetch(`/api/weather?lng=${lng}&lat=${lat}`);
  const data = await res.json();

  if (data.status === "1" && data.lives?.length > 0) {
    const info = data.lives[0];
    weather.value = `${info.city} ${info.weather} ${info.temperature}℃ 湿度 ${info.humidity}%`;
  } else {
    weather.value = "获取天气失败";
  }
});
</script>

<template>
  <div style="padding: 20px; font-size: 18px">
    <h2>天气查询</h2>
    <p>{{ weather }}</p>
  </div>
</template>

